package o;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.util.SparseArray;
import com.huawei.hms.support.api.entity.hwid.HwIDConstant.ACTION;
import java.util.LinkedHashMap;

public class dkg {
    private SparseArray<String> ˊ;

    public dkg() {
        this.ˊ = null;
        this.ˊ = new SparseArray(3);
        this.ˊ.put(1, "com.apkpure.aegon");
        this.ˊ.put(2, "cm.aptoide.pt");
        this.ˊ.put(3, "com.android.vending");
    }

    public boolean ˎ(Context context, String str, String str2, String str3, String str4) {
        if (context == null || TextUtils.isEmpty(str) || TextUtils.isEmpty(str2) || TextUtils.isEmpty(str3)) {
            Logger.ˎ("PackageGoogleLauncher", "cannot launch, because necessary");
            return false;
        } else if (ˎ(context, str, str2)) {
            Logger.ˎ("PackageGoogleLauncher", "launch success, deeplinkOrder: " + str);
            return true;
        } else {
            ˋ(str3, str4, str2);
            return ˊ(context, str3);
        }
    }

    private void ˋ(String str, String str2, String str3) {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put(dyr.BI_KEY_URL, str);
        linkedHashMap.put("detailID", str2);
        linkedHashMap.put("keyword", str3);
        dgh.ˋ("250801", linkedHashMap);
    }

    private boolean ˎ(Context context, String str, String str2) {
        String[] split = str.split(",");
        if (split.length == 0) {
            return false;
        }
        int length = split.length;
        int i = 0;
        while (i < length) {
            try {
                String str3 = (String) this.ˊ.get(Integer.parseInt(split[i]));
                if (TextUtils.isEmpty(str3)) {
                    Logger.e("PackageGoogleLauncher", "storePackageName is Empty, cannot get store packageName");
                    return false;
                } else if (ॱ(context, str2, str3)) {
                    return true;
                } else {
                    i++;
                }
            } catch (NumberFormatException e) {
                Logger.e("PackageGoogleLauncher", "NumberFormatException, cannot get store packageName");
                return false;
            }
        }
        return false;
    }

    private boolean ॱ(Context context, String str, String str2) {
        CharSequence charSequence = "[package]";
        return ˎ(context, ("market://details?id=" + charSequence).replace(charSequence, str), str2, true);
    }

    public boolean ˏ(Context context, String str, String str2) {
        if (ॱ(context, str)) {
            Logger.ˎ("PackageGoogleLauncher", "launchGoogleClient Successed");
            return true;
        }
        Logger.ˎ("PackageGoogleLauncher", "launchGoogleClient Failed,will launchGoogleWap");
        return ˊ(context, str2);
    }

    private boolean ˊ(Context context, String str) {
        return ˎ(context, str, null, false);
    }

    public boolean ॱ(Context context, String str) {
        CharSequence charSequence = "[package]";
        return ˎ(context, ("market://details?id=" + charSequence).replace(charSequence, str), "com.android.vending", true);
    }

    private boolean ˎ(Context context, String str, String str2, boolean z) {
        if (TextUtils.isEmpty(str)) {
            Logger.ˋ("PackageGoogleLauncher", "launchIntent isClient:" + z + " failed uriPath is " + str);
            return false;
        }
        Intent intent = new Intent(ACTION.HWID_SCHEME_URL);
        Uri parse = Uri.parse(str);
        Logger.ˏ("PackageGoogleLauncher", "launchIntent isClient:" + z + ",uriPath:" + str);
        intent.setData(parse);
        if (z) {
            if (!erz.ˏ(context, str2)) {
                Logger.ˋ("PackageGoogleLauncher", "launchIntent isClient:" + z + " failed, package " + str2 + " not installed.");
                return false;
            } else if (context.getPackageManager().getLaunchIntentForPackage(str2) == null) {
                Logger.ˋ("PackageGoogleLauncher", "launchIntent  client failed,it has not launcher Intent.");
                return false;
            } else {
                intent.setPackage(str2);
            }
        }
        if (!(context instanceof Activity)) {
            intent.addFlags(268435456);
        }
        try {
            context.startActivity(intent);
            return true;
        } catch (Exception e) {
            Logger.ˋ("PackageGoogleLauncher", "launchIntent isClient:" + z + ",ActivityNotFoundException:" + str);
            return false;
        }
    }
}
